package com.utilities.parsers;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;

import com.utilities.parsers.alignmentParser.ParseAllContigsFileParser;
import com.utilities.parsers.alignmentParser.ParseEvents;
import com.utilities.parsers.alignmentParser.ParseListener;

public class AlignmentExtractor extends ParseListener 
{
	private PrintWriter pw = null;
	private boolean flag = false;
	private StringBuffer buffer = new StringBuffer();

	/**
	 * @param args
	 * @throws IOException 
	 * @throws FileNotFoundException 
	 */
	public static void main(String[] args) throws FileNotFoundException, IOException 
	{
		AlignmentExtractor alignmentExtractor = new AlignmentExtractor();
		alignmentExtractor.service(args);
		
	}
	
	private void service(String[] args) throws FileNotFoundException, IOException
	{
		ParseAllContigsFileParser allContigsFileParser = new ParseAllContigsFileParser();
		allContigsFileParser.addListener(this);
		pw = new PrintWriter(args[1]);
		allContigsFileParser.parse(new FileReader(args[0]));
	}

	@Override
	public void handleEvent(ParseEvents event) 
	{
		switch((ParseEvents.EventTypes)event.getEventType())
		{
		case docStarted:
			break;
		case headerMarker:
			break;
		case alignedSequencesInfo:
			break;
		case beginAlignment:
			if (this.flag)
			{
				System.err.println("Two alignments found");
				System.exit(1);
			}
			this.flag = true;
			break;	
		case referenceSeq:
			break;
		case querySeq:
			break;
		case endAlignment:
			break;
		case docEnded:
			this.pw.flush();
			this.pw.close();
			break;	
		}
	}

}
